import { Injectable, Logger } from '@nestjs/common';
import * as amqp from 'amqplib';

@Injectable()
export class AppService {
  private readonly logger = new Logger(AppService.name); // ✅ 创建 logger 实例

  getHello(): string {
    return 'Hello World!';
  }

  private readonly queueName = 'video.transcode.queue';

  async sendTranscodeTask(videoId: string, originalPath: string) {
    const connection = await amqp.connect('amqp://localhost'); // RabbitMQ 地址
    const channel = await connection.createChannel();
    await channel.assertQueue(this.queueName, { durable: true });

    const msg = JSON.stringify({ videoId, originalPath });
    channel.sendToQueue(this.queueName, Buffer.from(msg));
    // ✅ 使用 logger 代替 console.log
    this.logger.log(`转码任务已发送: ${videoId}`);

    await channel.close();
    await connection.close();
  }
}
